package com.avic.rong.adapter.vadio_adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.avic.rong.R;
import com.shuyu.gsyvideoplayer.utils.GSYVideoHelper;

/**
 * Created by TSJ-2018-0492 on 2019/9/24.
 */

public class RecyclerItemViewHolder extends RecyclerItemBaseHolder{
    private GSYVideoHelper smallVideoHelper;

    ImageView imageView;
    public final static String TAG = "RecyclerView2List";
    private GSYVideoHelper.GSYVideoHelperBuilder gsySmallVideoHelperBuilder;
    protected Context context = null;
    private FrameLayout listItemContainer;
    private ImageView listItemBtn;

    public RecyclerItemViewHolder(@NonNull View itemView) {
        super(itemView);
    }

    public RecyclerItemViewHolder(Context context, View v) {
        super(v);
        this.context = context;
        listItemContainer = v.findViewById(R.id.list_item_container);
        listItemBtn = v.findViewById(R.id.list_item_btn);
        imageView = new ImageView(context);
    }
    public void onBind(final int position, VideoModel videoModel) {



        //增加封面

        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageResource(R.mipmap.deafult_image_header);
        smallVideoHelper.addVideoPlayer(position, imageView, TAG, listItemContainer, listItemBtn);
        listItemBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                smallVideoHelper.setPlayPositionAndTag(position, TAG);
                getRecyclerBaseAdapter().notifyDataSetChanged();
                //listVideoUtil.setLoop(true);
                String url;
                if (position % 2 == 0) {
                    url = "https://res.exexm.com/cw_145225549855002";
                } else {
                    url = "http://7xjmzj.com1.z0.glb.clouddn.com/20171026175005_JObCxCE2.mp4";
                }
                //listVideoUtil.setCachePath(new File(FileUtils.getPath()));
                gsySmallVideoHelperBuilder.setVideoTitle("title " + position).setUrl(url);
                smallVideoHelper.startPlay();
                //必须在startPlay之后设置才能生效
                //listVideoUtil.getGsyVideoPlayer().getTitleTextView().setVisibility(View.VISIBLE);
            }
        });
    }
    public void setVideoHelper(GSYVideoHelper smallVideoHelper, GSYVideoHelper.GSYVideoHelperBuilder gsySmallVideoHelperBuilder) {

        this.smallVideoHelper = smallVideoHelper;

        this.gsySmallVideoHelperBuilder = gsySmallVideoHelperBuilder;

    }
}
